import joi from 'joi'

const envVarsSchema = joi.object({
  PORT: joi.number()
    .default(8080),
  HOST: joi.string()
    .default('localhost')
}).unknown()
  .required()

const {
  error,
  value: envVars
} = joi.validate(process.env, envVarsSchema)
if (error) {
  throw new Error(`Config validation error: ${error.message}`)
}

const config = {
  server: {
    port: envVars.PORT,
    host: envVars.HOST
  }
}

module.exports = config
